﻿$(function () {
    
var _ind = 0;
var _len = $(".his-top .swiper-slide").length;

var leftbox_swiper = new Swiper('.his-top .swiper-container', {
    nextButton: '.his-top .swiper-button-next',
    prevButton: '.his-top .swiper-button-prev',
    slidesPerView:4,
    spaceBetween : 2,
    //direction :'vertical',
    //initialSlide :$(".history_year .his-top .swiper-slide").length,//设定初始化时slide的索引。
    breakpoints: { 
        1023: {
            slidesPerView: 3,
          },
        767: {
            slidesPerView: 2,
          }
    }
});
    

btnJudge();

$(".his-top .swiper-button-prev").click(function() {
    _ind--;
    btnJudge()
    $(".his-top .swiper-slide").eq(_ind).addClass("on").siblings().removeClass("on");
    $(".his-top .swiper-slide.on").click();
})

$('.his-top .swiper-button-next').click(function() {
    _ind++;
    btnJudge()
    $(".his-top .swiper-slide").eq(_ind).addClass("on").siblings().removeClass("on");
    $(".his-top .swiper-slide.on").click();
})

$(".his-top .swiper-slide").click(function(){
    _ind = $(this).index();
    $(this).addClass("on").siblings().removeClass("on");
    btnJudge();
    var url = $(this).data("src");
    if(url == ""){
      return false;
    }else{
      caseAjax(".his-cons",url);
    }
})
$(".his-top .swiper-slide").eq(0).click();


  


function btnJudge() {
    //console.log(_ind,_len)
    if(_ind >= _len - 1) {
        $('.his-top .swiper-button-next').addClass("disabled")
        _ind = _len - 1;
    } else {
        $('.his-top .swiper-button-next').removeClass("disabled")
    }
    if(_ind <= 0) {
        $(".his-top .swiper-button-prev").addClass("disabled")
        _ind = 0;
    } else {
        $(".his-top .swiper-button-prev").removeClass("disabled")
    }
}




})


//caseAjax
function caseAjax(str,url){
	$.ajax({
		url:url,
		success:function(msg){
			$(str).html("");
            $(str).append(msg);
            $(".his-cons li").each(function(){
                if($(this).find("img").size()<1){
                    $(this).addClass("noimg");
                }
            })
		}
	});
}



